<template>
  <div>
    <Navbar
      @callbackrole="callbackrole"
      @changrole="changrole"
    />
    <div class="background">
      <div class="content">
        <div class="left">
          <div class="top">
            <div class="icon">
              <img
                src="@/assets/app/ly.png"
                alt=""
              >
            </div>
            <div style="line-height:28px;font-weight:bold;color:#fff">
              {{ apps.name }}
            </div>
            <div style="color:#8CAEE2;padding:10px 0">
              {{ username }}
            </div>
            <div style="display:flex;justify-content:center">
              <div
                class="btn"
                @click="loginout"
              >
                退出
              </div>
            </div>
          </div>
          <div class="bottom">
            <div v-if="roleid==1 || roleid==2">
              <div class="bottom-box">
                <div class="icon">
                  <img
                    src="@/assets/app/email.png"
                    alt=""
                  >
                </div>
                <div>
                  <div class="num">
                    {{ info[0].tol }}
                  </div>
                  <div>接入用户数</div>
                </div>
              </div>
              <div class="bottom-box">
                <div class="icon">
                  <img
                    src="@/assets/app/upload.png"
                    alt=""
                  >
                </div>
                <div>
                  <div class="num">
                    {{ info[1].tol }}
                  </div>
                  <div>接入应用数</div>
                </div>
              </div>
              <!-- <div class="bottom-box">
                 <div class="icon">
                    <img src="@/assets/app/Calendar.png" alt="">
                  </div>
                  <div>
                      <div class="num">{{info[2].tol}} </div>
                      <div>昨天登录数</div>
                  </div>
              </div> -->
            </div>
          </div>
        </div>
        <div class="right">
          <div class="title">
            <div>应用入口</div>
            <div style="margin-left:10px;flex: 1;height:1px;background:#E8EEF7" />
          </div>
          <div class="contnet">
            <div
              v-for="item in apps.roleApp"
              :key="item.id"
              class="box"
            >
              <a
                :href="item.url+'?userId='+userId+'&tenantId='+tenantId+'&roleId='+item.roleId+'&appId='+item.appId+'&token='+token+'&type='+type"
                target="_blank"
              >
                <div class="icon">
                  <img
                    :src="item.icon"
                    alt=""
                  >
                </div>
                <div class="boxContent">
                  <div class="name">{{ item.appName }}<img
                    src="@/assets/app/arrow.png"
                    style="width: 13px;height: 10px;margin-left: 10px;"
                    alt=""
                  > </div>
                  <div class="time">{{ item.description }}</div>
                </div>
              </a>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="copyright">
      copyright 2020 江苏开拓信息与系统有限公司
    </div>
    <!-- app
    <el-button @click="getInfo">111</el-button> -->
  </div>
</template>
<script>
import Navbar from './component/Navbar'
import {  getInfo,getLoginInfo } from '@/api/user'
import {  getToken,removeToken } from '@/utils/auth'
export default {
  name:'App',
  components:{
    Navbar
  },
  data(){
    return{
      roleid:null,//1平台管理2租户管理3租户
      role:[],//应用角色,
      apps:{},
      tenantId:null,
      info:[], //登入日志
      type:null
    }
  },
  computed: {
    username(){
      return this.$store.getters.name
    },
    userId(){
      return this.$store.getters.userId
    },
    token(){
      return getToken()
    }
  },
  watch: {
    roleid(val){
      if(val){
        console.log(val)
      }

    }
  },
  created() {
  },
  methods: {
    getInfo(){
      getInfo(this.$store.getters.name).then(res=>{
      })
    },
    loginout(){
      removeToken()
    },
    callbackrole(data){
      this.roleid=data.type
      this.role=data.data
      this.type=data.type
      if(data.data.length>0){
        this.apps=data.data[0]
        this.tenantId=data.data[0].tenantId
        this.getApps()
      }

    },
    changrole(val){
      this.tenantId=val
      this.role.map(item=>{
        if(item.tenantId===val){
          this.apps=item
          this.getApps()
        }
      })
    },
    getApps(){
      if(this.roleid==1 || this.roleid==2){
        getLoginInfo({userId:this.$store.getters.userId,tenantId:this.apps.tenantId}).then(res=>{
                this.info=res.data
              })
      }

    }
  },
}
</script>
<style lang="scss" scoped>
img{
  width: 100%;
  height: 100%;
}
.copyright{
  position: absolute;
  left: 50px;
  -webkit-transform: scale(0.7);
transform: scale(0.7); //所需文字像素通过缩放实现
  bottom: 20px;
height:17px;
font-size:12px;
font-family:PingFang SC;
font-weight:400;
line-height:17px;
color:rgba(191,191,191,1);
}
.background{
  height:344px;
  background:#1D62C7;
  position: relative;
  .content{
    position: absolute;
    width: 100%;
    left: 0;
    top: 0;
    display: flex;
    .left{
      width: 394px;
      padding: 15px 60px;
      .top{
        padding:0 40px;
        text-align: center;
        height: 334px;
        .icon{
          width: 192px;
          height: 192px;
        }
        .btn{
          width:68px;
          height:32px;
          border:2px solid rgba(140,174,226,1);
          line-height: 28px;
          opacity:1;
          border-radius:16px;
          color:#8CAEE2;
          cursor: pointer;
        }
      }
      .bottom{
        padding-top: 20px;
        .bottom-box{
          display: flex;
          align-items: center;
          width:272px;
          height:92px;
          background:rgba(255,255,255,1);
          box-shadow:0px 3px 20px rgba(93,93,93,0.22);
          opacity:1;
          border-radius:6px;
          font-size:16px;
          margin: 20px 0px;
          color: #4A4A4A;
          .icon{
            width: 51px;
            height: 51px;
            margin: 0 31px;
          }
          .num{
            color:#1D62C7;
            font-size:22px;
            padding-bottom: 10px;
          }
        }
      }


    }
    .right{
      flex: 1;
      margin-top: 15px;
      margin-right: 20px;
      height:779px;
      background:rgba(255,255,255,1);
      box-shadow:0px 3px 20px rgba(93,93,93,0.22);
      opacity:1;
      border-radius:20px;
      padding: 40px;
      .title{
        color: #252934;
        height: 50px;
        display: flex;
        align-items: center;

      }
      .contnet{
        display: flex;
        align-content: flex-start;
        flex-wrap: wrap;
        overflow: hidden;
        overflow-y: scroll;
        height: calc(100% - 100px);
      }
      .contnet::-webkit-scrollbar {
        width: 2px;
        height: 16px;
        background-color: #ccc;

        }
      .box{
        width: calc(50% - 40px);
        margin:0 20px;
        margin-bottom: 17px;
        height:104px;
        background:rgba(255,255,255,1);
        border:1px solid rgba(236,238,245,1);
        box-shadow:0px 5px 10px rgba(178,183,209,0.2);
        border-radius:10px;
        >a{
           display: flex;
          align-items: center;
          padding: 17px;
          cursor: pointer;
        }

        .icon{
          width: 70px;
          height: 70px;
          border:1px solid rgba(233,233,233,1);
        }
        .boxContent{
          padding-left: 20px;
          .name{
            font-size:16px;
            color: #252934;
            font-weight: 500;
          }
          .time{
            color:#A4A4A4;
            padding-top: 10px;
            font-size:14px;
          }
        }

      }
    }
  }
}
</style>
